package com.exercise.demo.delegate;

import com.exercise.demo.delegate.SmsService;
import com.exercise.demo.delegate.SmsServiceImpl;
import com.exercise.demo.delegate.dynamicDelegate.cglibDynamicDelegate.AliSmsService;
import com.exercise.demo.delegate.dynamicDelegate.cglibDynamicDelegate.CglibProxyFactory;
import com.exercise.demo.delegate.dynamicDelegate.jdkDynamicDelegate.JdkProxyFactory;
import com.exercise.demo.delegate.staticDelegate.SmsProxy;

/**
 * @author dale
 * @Date 2021-05-18 11:06
 **/
public class SmsMain {
    public static void main(String[] args) {
//        jdkDynamicDelegate();
        cglibDynamicDelegate();
    }

    public static void staticDelegate() {
        SmsService smsService=new SmsServiceImpl();
        SmsProxy smsProxy= new SmsProxy(smsService);
        smsProxy.send("this is message send test");
    }

    public static void jdkDynamicDelegate() {
        SmsService smsService = (SmsService)JdkProxyFactory.getProxy(new SmsServiceImpl());
        smsService.send("jdk");
    }

    public static void cglibDynamicDelegate(){
        AliSmsService aliSmsService = (AliSmsService) CglibProxyFactory.getProxy(AliSmsService.class);
        aliSmsService.send("java");

    }
}
